package com.idea.zd.sys.train;

public class SortMethod {


    public void print(int a[]){
        for(int i=0;i<a.length;i++){
            System.out.print(a[i]+" ");
        }
    }

    public void insertSort(int[] array){
        System.out.println("排序前:");
        print(array);

        for(int i= 0;i< array.length;i++){

            int j;
            int x = array[i];

            for(j= i;j > 0 && x< array[j-1];j--){
                array[j]= array[j-1];
            }
            array[j]=x;

        }

        System.out.println("排序后:");
        print(array);


    }

    public static void main(String[] args){
        int a[] = {3,1,5,7,2,4,9,6,10,8};
        SortMethod sortMethod = new SortMethod();
        sortMethod.insertSort(a);
    }
}
